package demo3;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Enumeration;

@WebServlet("/hello3")
public class Test extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        StringBuilder builder = new StringBuilder();
        builder.append(req.getProtocol());
        builder.append("<br>");
        builder.append(req.getMethod());
        builder.append("<br>");
        builder.append(req.getRequestURI());
        builder.append("<br>");
        builder.append(req.getContextPath());
        builder.append("<br>");
        builder.append(req.getQueryString());
        builder.append("<br>");

        Enumeration<String> headernames = req.getHeaderNames();
        while (headernames.hasMoreElements()) {
            String key = headernames.nextElement();
            String value = req.getHeader(key);
            builder.append(key).append("=").append(value).append("<br>");
        }

        resp.setContentType("text/html;charset=UTF-8");
        resp.getWriter().write(builder.toString());
    }
}
